using System;
using System.Collections.Generic;
using System.Text;
using Utilities.Collections;
using Utilities.Testing;
using NUnit.Framework;
using Utilities.Miscellaneous;

namespace Utilities.Test.Collections
{
  public class MultiComparerFixture : TestFixtureBase
  {
    [Test]
    public void DateTimeComparer()
    {
      PropertyComparer<DateTime, int> yearComparer = new PropertyComparer<DateTime, int>(
        delegate(DateTime d) { return d.Year; }
      );

      PropertyComparer<DateTime, int> minuteComparer = new PropertyComparer<DateTime, int>(
        delegate(DateTime d) { return d.Minute; }
      );

      MultiComparer<DateTime> multiComparer = new MultiComparer<DateTime>(new IComparer<DateTime>[] { yearComparer, minuteComparer });

      List<DateTime> test = new List<DateTime>();

      for (int i = 0; i < 100; i++)
      {
        test.Add(RandomUtils.GetDateTime());
      }

      test.Sort(multiComparer);

      for (int i = 0; i < 99; i++)
      {
        DateTime d1 = test[i];
        DateTime d2 = test[i + 1];

        int yearCompare = Comparer<int>.Default.Compare(d1.Year, d2.Year);

        Assert.AreNotEqual(yearCompare, 1);

        if (yearCompare == 0)
          Assert.AreNotEqual(Comparer<int>.Default.Compare(d1.Minute, d2.Minute), 1);
      }
    }
  }
}
